import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
import Nprogress from 'nprogress'
import "nprogress/nprogress.css"
Vue.use(VueRouter)
// 解决vue2重复跳转路由报错
const originaPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originaPush.call(this, location).catch(err => err)
}
let router = new VueRouter({
	routes: [{
		path: '/',
		name: 'Layout',
		component: () => import('@/views/layout/layout'),
		children: [{
			// 首页
			path: "/",
			name: "Home",
			component: () => import('@/views/home/home')
		}, {
			// 优课详情
			path: "/fineCourse/courseInfo",
			name: "CourseInfo",
			component: () => import('@/views/fineCourse/courseInfo')
		}, {
			// 确认订单
			path: "/confirmOrder",
			name: "ConfirmOrder",
			component: () => import('@/views/fineCourse/confirmOrder')
		}, {
			// 优课列表
			path: "/fineCourse/courseList",
			name: "CourseList",
			component: () => import('@/views/fineCourse/courseList')
		},  {
			// 辅导详情
			path: "/fineCourse/coach",
			name: "Coach",
			component: () => import('@/views/fineCourse/coach')
		}, {
			// 资料列表
			path: "/information/informationList",
			name: "InformationList",
			component: () => import('@/views/information/informationList')
		}, {
			// 资料详情
			path: "/information/informationInfo",
			name: "InformationInfo",
			component: () => import('@/views/information/informationInfo')
		}, {
			// 测试列表
			path: "/test/testList",
			name: "TestList",
			component: () => import('@/views/test/testList')
		}, {
			// 测试详情
			path: "/test/testInfo",
			name: "TestInfo",
			component: () => import('@/views/test/testInfo')
		},{
			// 搜索列表
			path: "/search/searchList",
			name: "SearchList",
			component: () => import('@/views/search/searchList')
		}, {
			// 老师主页
			path: "/teacher/teacherInfo",
			name: "TeacherInfo",
			component: () => import('@/views/teacher/teacherInfo')
		}, {
			// 提问
			path: "/questioning",
			name: "Questioning",
			component: () => import('@/views/questioning')
		}, {
			// 提问-指定老师提问
			path: "/questioning/appointTeacher",
			name: "AppointTeacher",
			component: () => import('@/views/questioning/appointTeacher')
		}, {
			// 论坛
			path: "/forum",
			name: "Forum",
			component: () => import('@/views/forum')
		},  {
			// 论坛详情
			path: "/forum/forumInfo",
			name: "ForumInfo",
			component: () => import('@/views/forum/forumInfo')
		},  {
			// 论坛-我的发布
			path: "/forum/mineRelease",
			name: "ForumMineRelease",
			component: () => import('@/views/forum/mineRelease')
		}, {
			// 商城
			path: "/shopping",
			name: "Shopping",
			component: () => import('@/views/shopping')
		}, {
			// 商城-商品详情
			path: "/shopping/goodsInfo",
			name: "GoodsInfo",
			component: () => import('@/views/shopping/goodsInfo')
		}, {
			// 商城-确认订单
			path: "/shopping/goodsConfirmOrder",
			name: "confirmOrder",
			component: () => import('@/views/shopping/goodsConfirmOrder')
		}, {
			// 测试-开始考试
			path: "/startTest",
			name: "StartTest",
			component: () => import('@/views/test/startTest')
		},{
			// 测试-考试提交后
			path: "/endText",
			name: "endText",
			component: () => import('@/views/test/endText')
		}, {
			// 测试-考试中
			path: "/testing",
			name: "Testing",
			component: () => import('@/views/test/testing')
		},{
			// 测试-查看试卷
			path: "/seePaper",
			name: "seePaper",
			component: () => import('@/views/test/seePaper')
		}, {
			// 我的错题列表
			path: "/wrongQuestion",
			name: "WrongQuestion",
			component: () => import('@/views/wrongQuestion'),
		}, {
			// 个人中心
			path: "/mine",
			name: "Mine",
			component: () => import('@/views/mine/mine'),
			children: [{
				// 个人信息
				path: "/mine/mineMessage",
				name: "MineMessage",
				component: () => import('@/views/mine/mineMessage'),
			}, {
				// 学习订单
				path: "/mine/studyOrder",
				name: "StudyOrder",
				component: () => import('@/views/mine/studyOrder'),
			}, {
				// 学习订单-详情
				path: "/mine/studyOrderInfo",
				name: "StudyOrderInfo",
				component: () => import('@/views/mine/studyOrderInfo'),
			}, {
				// 学习记录
				path: "/mine/studyRecord",
				name: "StudyRecord",
				component: () => import('@/views/mine/studyRecord'),
			}, {
				// 商城订单
				path: "/mine/shoppingOrder",
				name: "ShoppingOrder",
				component: () => import('@/views/mine/shoppingOrder'),
			}, {
				// 商城订单-详情
				path: "/mine/shoppingOrderInfo",
				name: "ShoppingOrderInfo",
				component: () => import('@/views/mine/shoppingOrderInfo'),
			}, {
				// 我的提问
				path: "/mine/mineQuestion",
				name: "MineQuestion",
				component: () => import('@/views/mine/mineQuestion'),
			}, {
				// 我的提问-回答
				path: "/mine/mineQuestionAnswer",
				name: "MineQuestionAnswer",
				component: () => import('@/views/mine/mineQuestionAnswer'),
			}, {
				// 我的老师
				path: "/mine/mineTeacher",
				name: "MineTeacher",
				component: () => import('@/views/mine/mineTeacher'),
			}, {
				// 我的老师-审核进度
				path: "/mine/mineTeacherProcess",
				name: "MineTeacherProcess",
				component: () => import('@/views/mine/mineTeacherProcess'),
			}, {
				// 我的考试
				path: "/mine/mineExamination",
				name: "MineExamination",
				component: () => import('@/views/mine/mineExamination'),
			}, {
				// 学习考试卡
				path: "/mine/studyExamCard",
				name: "StudyExamCard",
				component: () => import('@/views/mine/studyExamCard'),
			}, {
				// 购买记录
				path: "/mine/buyRecord",
				name: "BuyRecord",
				component: () => import('@/views/mine/buyRecord'),
			}, {
				// 我的错题
				path: "/mine/mineWrongQuestion",
				name: "MineWrongQuestion",
				component: () => import('@/views/mine/mineWrongQuestion'),
			},  {
				// 我的余额
				path: "/mine/mineBalance",
				name: "MineBalance",
				component: () => import('@/views/mine/mineBalance/index'),
				children: [{
					// 我的余额-余额明细
					path: "/mine/mineBalance",
					name: "TableList",
					component: () => import(
						'@/views/mine/mineBalance/tableList'),
				}, {
					// 我的余额-充值
					path: "/mineBalance/recharge",
					name: "Recharge",
					component: () => import(
						'@/views/mine/mineBalance/recharge'),
				}, {
					// 我的余额-提现
					path: "/mineBalance/withdrawal",
					name: "Withdrawal",
					component: () => import(
						'@/views/mine/mineBalance/withdrawal'),
				}, ],
			}, ]
		}, {
			// 设置
			path: "/mine/setUp",
			name: "SetUp",
			component: () => import('@/views/mine/setUp/index'),
			children:[{
				// 隐私协议、关于我们、用户协议、问题详情
				path: "/setUp/agreement/:type",// type=1隐私协议 type=2关于我们 type=3用户协议 type=4
				name: "Agreement",
				component: () => import('@/views/mine/setUp/agreement'),
			},{
				// 帮助中心详情
				path: "/setUp/helpdetail",
				name: "helpdetail",
				component: () => import('@/views/mine/setUp/helpdetail'),
			},{
				// 收货地址
				path: "/setUp/address",
				name: "Address",
				component: () => import('@/views/mine/setUp/address'),
			},{
				// 黑名单管理
				path: "/setUp/blacklistManage",
				name: "BlacklistManage",
				component: () => import('@/views/mine/setUp/blacklistManage'),
			},{
				// 帮助中心
				path: "/setUp/help",
				name: "Help",
				component: () => import('@/views/mine/setUp/help'),
			},{
				// 意见反馈
				path: "/setUp/feedback",
				name: "Feedback",
				component: () => import('@/views/mine/setUp/feedback'),
			},{
				// 历史反馈
				path: "/setUp/historyFeedback",
				name: "HistoryFeedback",
				component: () => import('@/views/mine/setUp/historyFeedback'),
			},]
		}, {
			// 评价订单
			path: "/evaluateOrder",
			name: "EvaluateOrder",
			component: () => import('@/views/evaluateOrder/evaluateOrder'),
		}, {
			// 我的收藏
			path: "/mine/mineCollect",
			name: "MineCollect",
			component: () => import('@/views/mine/mineCollect'),
		}, {
			// 消息
			path: "/message",
			name: "Message",
			component: () => import('@/views/message'),
		}, ]
	}, {
		// 登录
		path: '/login',
		name: 'Login',
		component: () => import('@/views/login/login')
	}]
})
// 使用全局路由守卫判断当前用户登录状态  若未登录则强制跳转登录页面
router.beforeEach((to, from, next) => {
    // let name = to.name
    // let list = navList[name]
    // store.commit("setNavList",list)
    // 开始加载页面进度条
    Nprogress.start();
    if (to.path == '/forum') {
        // 判断当前用户是否登录
        if (store.state.token) {
            return next();
        }
        // return next("/login")
        return router.push({
			path:"/login"
		})
		
    }
    return next();
})
router.afterEach((to, from) => {
    // 结束进度条
    Nprogress.done();
})


export default router